<template>
  <div class="categorylist">
    <!-- 搜索的 -->
    <van-search
      shape="round"
      show-action
      background="#E83223"
      placeholder="搜索商品信息"
      @focus="$router.push('/search')"
    >
      <template #action>
        <div @click="show = !show" class="hhl">
          <!-- <i class="fa fa-list" aria-hidden="true"></i> -->
          <van-icon color="#fff" v-if="show" name="qr" />
          <van-icon color="#fff" v-else name="apps-o" />
          <!-- <van-icon name="apps-o" /> -->
        </div>
      </template>
    </van-search>
    <!-- 为你推荐组件 -->
    <notshop v-if="shop.length == 0"></notshop>
    <div v-else class="haveshop">
      <!-- 横向排版 -->
      <router-link tag="div" :to="`/ProductDetails/${shops.id}`" v-show="show" v-for="shops in shop" :key="shops.id">
        <van-card
          :title="shops.store_name"
          :price="shops.price"
          :thumb="shops.image"
        >
          <template #bottom>
            <div class="navbox">
              <span>￥{{ shops.vip_price }}</span>
              <img
                v-show="shops.price != 0"
                src=""
                alt=""
              />
              <p>已售{{ shops.sales }}</p>
            </div>
          </template>
        </van-card>
      </router-link>
      <!-- 竖向排版 -->
      <div  v-show="!show" class="recommends">
        <router-link tag="div" :to="`/ProductDetails/${lists.id}`" class="shopping" v-for="lists in shop" :key="lists.id">
          <van-image class="image2" :src="lists.image"></van-image>
          <div class="shoptext">
            <b>{{ lists.store_name }}</b>
            <p>￥{{ lists.price }}</p>
            <div class="navbox2">
              <span>￥{{ lists.vip_price }}</span>
              <img
                v-show="lists.price != 0"
                src=""
                alt=""
              />
              <p>已售{{ lists.sales }}</p>
            </div>
          </div>
        </router-link>
      </div>
    </div>
  </div>
</template>
<script>
// 为你推荐组件
import notshop from "../components/recommend_of_you.vue";

export default {
  props: {
    seachid: String,
  },
  data() {
    return {
      shop: [],
      show: false,
    };
  },
  created() {
    this.axios
      .get(`http://47.115.51.185/api/products?&keyword=&sid=${this.seachid}`)
      .then((result) => {
        console.log("分类的列表", result);
        this.shop = result;
      });
  },
  methods: {},
  components: {
    notshop,
  },
};
</script>
<style lang="less" scoped>
.categorylist {
  width: 100vw;
  height: 90vh;
  background-color: #f4f4f4;
  .van-search__action {
    margin: 0px 10px;
    padding: 0px;
    .hhl {
      background-color: #e83223;
      font-size: 28px;
    }
  }

  .haveshop {
    div {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      .van-card__title {
        padding-top: 5px;
        display: block;
        font-size: 16px;
        width: 100%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      .van-card__price {
        color: red;
        font-weight: 700;
      }
    }
    .van-card__bottom {
      .navbox {
        position: relative;

        img {
          margin-left: 3px;
          width: 23px;
          height: 10.5px;
        }
        span {
          color: #272727;
          font-size: 14px;
          font-weight: 500;
        }
        p {
          font-size: 12px;
          position: absolute;
          right: 10px;
          top: 50%;
          color: #a9a9a9;
          transform: translateY(-50%);
        }
      }
      .navbotbox {
        .van-icon {
          font-size: 28px;
          color: rgb(236, 91, 91);
          font-weight: normal;
        }
      }
    }
    //竖向排版
    .recommends {
      padding: 20px 15px;
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;

      .shopping {
        width: 165px;
        margin-bottom: 10px;
        border-radius: 5px;
        .image2 {
          width: 165px;
          height: 165px;
          display: block;
        }
      }
      .shoptext {
        background-color: #fff;
      }
      b {
        display: block;
        font-size: 0.45rem;
        color: #282828;
        margin: 0.2rem 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        padding-left: 5px;
      }
      p {
        font-weight: 700;
        padding-left: 5px;
        font-size: 0.45rem;
        color: #fc4141;
      }
      .navbox2 {
        padding-left: 5px;
        position: relative;
        padding-bottom: 10px;
        img {
          margin-left: 3px;
          width: 23px;
          height: 10.5px;
        }
        span {
          color: #272727;
          font-size: 14px;
          font-weight: 600;
        }
        p {
          font-size: 12px;
          position: absolute;
          right: 10px;
          top: 50%;
          color: #a9a9a9;
          transform: translateY(-60%);
        }
      }
    }
  }
}
</style>